<template>
  <div>
    <button @click="test">测试all_info</button>
    <button @click="test2">测试login</button>
    <button @click="test3">测试data_auth_search</button>
    <button @click="test4">测试update_delete_info</button>
    <button @click="test5">测试Excel</button>
    <br>
    <button @click="test6">测试seatsoperations</button>
    <button @click="test6_3">测试seatsoperations查询seatid</button>
    <button @click="test6_2">测试seatsoperations-put</button>
    <br>
    <button @click="test7">测试personoperations</button>
    <br>
    <button @click="test8">测试checkseat有座</button>
    <button @click="test8_2">测试checkseat空座</button>
    <button @click="test8_3">测试checkseat无座</button>
    <br>
    <button @click="test9">测试changeAuthcode</button>
    <br>
    <br>
    <button @click="test10">测试changeBmks</button>
    <br>
    <br>

    <!-- <p v-html="$xss(test10)"></p> -->
    <br>
  </div>
</template>

<script>
import qs from 'qs'
export default {
  name: 'test',
  data() {
    return {
      loginInfo: {
        username: "",
        password: ""
      },
      params: {
        page: 1,
        // pageSize: 15,
        searchText: "",
        department: '',
        section: ''
      },
      editData: {
        department: "",
        email: null,
        mobile: "",
        name: "",
        position: null,
        seatinfo: {
          id: 0,
          ipaddress: "",
          phonenumber: "",
          roomnumber: "",
          roomname: "",
          roomnumber: "",
          seatid: ""
        },
        section: "",
      },
      // test10: `<a onclick='alert("xss攻击")'>链接</a>`
    }
  },
  created() {
    // let date = new Date();
    // console.log('date==>', date.getTime())
    // let date1 = new Date();
    // console.log('date1==>', date1.getTime());
    // date.setSeconds(date.getSeconds() + 60);
    // let date2 = date.getTime();
    // console.log('date==>', date);
    // console.log('date1==>', date1);
    // console.log('date2==>', date2);
    // console.log('cha==>', parseInt((date2 - date1)/1000), 's')
  },
  methods: {
    // all_info
    test() {
      this.axios({
        method: 'POST',
        url: '/api/all_info/',
        data: this.$qs.stringify({
          page: 1, department: '', section: '', searchText: ''
        })
      }).then(res => {
        // console.log('res==>', res)
        this.$message({
          message: res.data.msg,
          // type: 'success'
        });
      }).catch(error => {
        // console.log('error==>', error)
        this.$message({
          message: error,
          type: 'error'
        });
      })
    },
    // login
    test2() {
      this.axios({
        method: 'POST',
        url: '/api/login/',
        data: qs.stringify(this.loginInfo),
        headers: {
          // 'X-Requested-With': 'XMLHttpRequest',
          'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        },
      }).then(res => {
        // console.log('res==>', res)
        this.$message({
          message: res.data.msg,
          // type: 'success'
        });
      }).catch(error => {
        // console.log('error==>', error)
        this.$message({
          message: error,
          type: 'error'
        });
      })
    },
    // data_auth_search
    test3() {
      // headers: {
      // 'Authorization': this.$cookies.get('__tk')
      // },
      let data = {
        username: this.$cookies.get('__un'),
        authorizecode: this.$cookies.get('__ac'),
        page: 1
      };
      // console.log(data)
      this.axios({
        method: 'get',
        url: '/api/data_auth_search/',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Token': this.$cookies.get('__tk')
        },
        params: data
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    //update_delete_info
    test4() {
      // let seatinfo = this.$qs.stringify({
      //       id: 431,
      //       ipaddress: "暂无",
      //       phonenumber: "3065530",
      //       roomname: "暂无",
      //       roomnumber: "0000000",
      //       seatid: "000000",
      //     });
      this.axios({
        method: 'put',
        url: '/api/update_delete_info/',
        headers: {
          // 'Authorization': this.$cookies.get('__tk')
          'Token': this.$cookies.get('__tk')
        },
        data: {
          department: "",
          email: "",
          id: 0,
          mobile: "",
          name: "",
          position: "",
          seatinfo: {
            id: 0,
            ipaddress: "",
            phonenumber: "",
            roomname: "",
            roomnumber: "",
            seatid: "",
          }
        }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // 上传Excel
    test5() {
      this.axios({
        method: 'post',
        url: '/api/updatedb/',
        headers: {
          // 'Authorization': this.$cookies.get('__tk')
          'Token': this.$cookies.get('__tk')
        },

      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // seatsoperations
    test6() {
      this.axios({
        method: 'get',
        url: '/api/seatsoperations/',
        headers: {
          // 'Authorization': this.$cookies.get('__tk')
          'Token': this.$cookies.get('__tk')
        },
        params: { page: 1, hasman: 0, seatid: '0' }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // seatsoperations
    test6_3() {
      this.axios({
        method: 'get',
        url: '/api/seatsoperations/',
        headers: {
          // 'Authorization': this.$cookies.get('__tk')
          'Token': this.$cookies.get('__tk')
        },
        params: { page: 1, seatid: '1111111' }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // seatsoperations-put
    test6_2() {
      this.axios({
        method: 'put',
        url: '/api/seatsoperations/',
        headers: {
          // 'Authorization': this.$cookies.get('__tk')
          'Token': this.$cookies.get('__tk')
        },
        data: {
          // id: 3874,
          seatid: "",
          roomnumber: "",
          roomname: "",
          phonenumber: ""
        },
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // personoperations
    test7() {
      this.axios({
        method: 'POST',
        url: '/api/personoperations/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        data: this.$qs.stringify({
          department: "",
          email: null,
          mobile: "",
          name: "",
          position: null,
          seatinfo: JSON.stringify({
            id: 0,
            ipaddress: "",
            phonenumber: "",
            roomnumber: "",
            roomname: "",
            roomnumber: "",
            seatid: ""
          }),
          section: "",
        })
      }).then(res => {
        // console.log('res==>', res)
        this.$message({
          message: res.data.msg,
          // type: 'success'
        });
      }).catch(error => {
        // console.log('error==>', error)
        this.$message({
          message: error,
          type: 'error'
        });
      })
    },
    // check
    test8() {
      this.axios({
        method: 'get',
        url: '/api/checkseatid/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        params: { seatid: '3205001' }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // check
    test8_2() {
      this.axios({
        method: 'get',
        url: '/api/checkseatid/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        params: { seatid: '' }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },
    // check
    test8_3() {
      this.axios({
        method: 'get',
        url: '/api/checkseatid/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        params: { seatid: '' }
      }).then(res => {
        // console.log('res==>', res)
      }).catch(error => {
        // console.log('error==>', error)
      })
    },

    // 
    test9() {
      let data = {
        mobile: '',
        authorizecode: 0
      }
      // console.log('authcode data==>', data)
      // console.log('修改权限请求-----------------')
      this.axios({
        method: 'post',
        url: '/api/authchange/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        data: this.$qs.stringify(data)
      }).then(res => {
        // console.log('auth res==>', res)
        if (res.data.code != 200) {
          this.$message.error(res.data.msg)
          return
        }
      }).catch(error => {
        // console.log('error==>', error)
      });


    },

    // 
    test10() {
      this.axios({
        method: 'GET',
        url: '/api/dpsinfo/',
        headers: {
          'Token': this.$cookies.get('__tk')
        },
        params: {
          username: '13655555555'
        }
      }).then(res => {
        // console.log('checkBmks res==>', res)
        if (res.data.code == 200) {

          // console.log('dpsinfo==>', this.options.department)
        } else {
          this.$message.warning('请询问相关人员');
          resolve([])
        }
      }).catch(error => {
        // console.log('error==>', error)
        this.loading = false;
        this.$message.error(error || "出现错误，请稍后再试")
        resolve([])
      })
    },
  },
}
</script>

<style lang="scss" scoped>
</style>